<script>
export default {
  data() {
    return {
      pageNum: 1,
      pageSize: 5,
      total: 0,
      patrolTaskModel: {},
      patrolTaskList: [],
      dialogFormVisible: false,
      form: {},
      title: '',
      pointDialog: false,
      taskPointList: [],
      checkDialog: false,
      check:{}
    }
  },
  methods: {
    list() {
      this.$axios.post('/patrolTask', {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          ...this.patrolTaskModel
      })
          .then(res => {
            this.patrolTaskList = res.data.data.list
            this.total = res.data.data.total
          })
    },
    handleSizeChange(num) {
      this.pageSize = num
      this.list()
    },
    handleCurrentChange(num) {
      this.pageNum = num
      this.list()
    },
    add() {
      this.$axios.post('/patrolPoint', this.form)
          .then(res => {
            this.list()
            this.dialogFormVisible = false
            this.$message.success('添加成功')
          })
    },
    showUpdate(row) {
      this.title = '修改'
      this.form = {...row}
      this.dialogFormVisible = true
    },
    update() {
      this.$axios.put('/patrolPoint', this.form)
          .then(res => {
            this.list()
            this.dialogFormVisible = false
            this.$message.success('修改成功')
          })
    },
    del(row) {
      this.$confirm('确认要删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$axios.delete('/patrolPoint/' + row.id)
            .then(res => {
              this.list()
              this.$message.success('删除成功')
            })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });

    },
    showPoint(row) {
      this.$axios.get('/patrolPoint/task/' + row.id)
          .then(res => {
            this.taskPointList = res.data.data
            this.pointDialog = true
          })
    },
    updateStatu(row, statu) {
      this.$axios.put('/patrolTask/',{
        id: row.id,
        taskstatu: statu
      }).then(res => {
        this.list()
        this.$message.success('操作成功')
      })
    },
    getCheck(row) {
      this.$axios.get('/patrolcheck/taskId/' + row.id)
          .then(res => {
            this.check = res.data.data
            this.checkDialog = true
          })
    },
  },
  mounted() {
    this.list()
  }
}
</script>

<template>
  <div>
    <el-form :model="patrolTaskModel" inline>
      <el-form-item label="任务编号">
        <el-input v-model="patrolTaskModel.taskno" clearable></el-input>
      </el-form-item>
      <el-form-item label="任务名称">
        <el-input v-model="patrolTaskModel.taskname" clearable></el-input>
      </el-form-item>
      <el-form-item label="任务类型">
        <el-select v-model="patrolTaskModel.tasktype" clearable>
          <el-option value="plan" label="计划任务"></el-option>
          <el-option value="temp" label="紧急任务"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="任务状态">
        <el-select v-model="patrolTaskModel.taskstatu" clearable>
          <el-option value="0" label="待执行"></el-option>
          <el-option value="1" label="执行中"></el-option>
          <el-option value="2" label="等待审核"></el-option>
          <el-option value="3" label="审核通过"></el-option>
          <el-option value="4" label="审核未通过"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="开始时间">
        <el-date-picker
            v-model="patrolTaskModel.startdate"
            type="daterange"
            clearable
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间">
        <el-date-picker
            v-model="patrolTaskModel.enddate"
            type="daterange"
            clearable
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-button @click="list()" type="primary">查询</el-button>
      <el-button @click="patrolTaskModel={}" type="info">清空</el-button>
    </el-form>
    <el-table
        :data="patrolTaskList"
        style="width: 100%">
      <el-table-column
          prop="id"
          label="序号"
          width="80px"
      >
      </el-table-column>
      <el-table-column
          prop="taskno"
          label="任务编号">
      </el-table-column>
      <el-table-column
          prop="taskname"
          label="任务名称">
      </el-table-column>
      <el-table-column
          label="任务类型">
        <template slot-scope="{row}">
          {{ row.tasktype == 'plan' ? '计划任务' : '紧急任务' }}
        </template>
      </el-table-column>
      <el-table-column
          label=任务状态>
        <template slot-scope="scope">
          <el-tag type="info" v-if="scope.row.taskstatu == 0">待执行</el-tag>
          <el-tag type="warning" v-if="scope.row.taskstatu == 1">执行中</el-tag>
          <el-tag type="primary" v-if="scope.row.taskstatu == 2">等待审核</el-tag>
          <el-tag type="success" v-if="scope.row.taskstatu == 3">审核通过</el-tag>
          <el-tag type="danger" v-if="scope.row.taskstatu == 4">审核不通过</el-tag>
        </template>
      </el-table-column>
      <el-table-column
          prop="startdate"
          label="开始时间">
      </el-table-column>
      <el-table-column
          prop="enddate"
          label="结束时间">
      </el-table-column>
      <el-table-column
        label="巡检点">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="showPoint(scope.row)" round plain>查看巡检点</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="{row}">
          <el-button v-if="row.taskstatu==0" size="mini" type="success" @click="updateStatu(row,1)">开始执行</el-button>
          <el-button v-if="row.taskstatu==1" size="mini" type="warning" @click="updateStatu(row,2)">提交任务</el-button>
          <el-button v-if="row.taskstatu==2||row.taskstatu==4" size="mini" type="primary" @click="updateStatu(row,2)">重新提交</el-button>
          <el-button v-if="row.taskstatu==3||row.taskstatu==4" size="mini" type="info" @click="getCheck(row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>
    <el-dialog :title="title" :visible.sync="dialogFormVisible" width="500px">
      <el-form :model="form" label-width="auto">
        <el-form-item label="巡检点编号">
          <el-input v-model="form.pointno"></el-input>
        </el-form-item>
        <el-form-item label="巡检点名称">
          <el-input v-model="form.pointname"></el-input>
        </el-form-item>
        <el-form-item label="巡检点地址">
          <el-input v-model="form.address"></el-input>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="form.remark"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="title=='添加'?add():update()">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog title="巡检点信息" :visible.sync="pointDialog">
      <el-table :data="taskPointList">
        <el-table-column
            prop="pointno"
            label="巡检点编号"
            width="180">
        </el-table-column>
        <el-table-column
            prop="pointname"
            label="巡检点名称"
            width="180">
        </el-table-column>
        <el-table-column
            prop="address"
            label="巡检点地址">
        </el-table-column>
        <el-table-column
            prop="remark"
            label="备注">
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="pointDialog=false">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog title="信息" :visible.sync="checkDialog">
      <el-descriptions :column="2">
        <el-descriptions-item label="审核结果">{{ check.ckresult }}</el-descriptions-item>
        <el-descriptions-item label="审核时间">{{ check.ckdate }}</el-descriptions-item>
        <el-descriptions-item label="审核建议">{{ check.ckadvice }}</el-descriptions-item>
      </el-descriptions>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="checkDialog=false">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<style>

</style>